package org.example.config2;

import org.springframework.security.web.authentication.WebAuthenticationDetails;

import javax.servlet.http.HttpServletRequest;

/**
 * @Auther: GongXl
 * @Date: 2021/3/23 10:07
 * @Description:
 * 这边前三个参数是从页面的login请求中传过来的，
 * 后面两个参数是在页面上请求生成图片验证码的时候我们设置到session里面去，
 * 以便于后续的验证
 */
public class MyWebAuthenticationDetails extends WebAuthenticationDetails {
    /**
     *
     */
    private static final long serialVersionUID = 6975601077710753878L;

    private String username;

    private String password;
//验证码
    private String validcode;

    private String sessionCodeValue;

    private long sessionCodeTime;
    private String jwtToken;

    public String getSessionCodeValue() {
        return sessionCodeValue;
    }

    public void setSessionCodeValue(String sessionCodeValue) {
        this.sessionCodeValue = sessionCodeValue;
    }

    public long getSessionCodeTime() {
        return sessionCodeTime;
    }

    public void setSessionCodeTime(long sessionCodeTime) {
        this.sessionCodeTime = sessionCodeTime;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getValidcode() {
        return validcode;
    }

    public void setValidcode(String validcode) {
        this.validcode = validcode;
    }

    public String getJwtToken() {
        return jwtToken;
    }

    public void setJwtToken(String jwtToken) {
        this.jwtToken = jwtToken;
    }

    public MyWebAuthenticationDetails(HttpServletRequest request) {
        super(request);
        username = request.getParameter("username");
        password = request.getParameter("password");
        validcode = request.getParameter("validateCode");

        System.out.println("获得验证码的session:"+request.getSession().getId());
        sessionCodeValue = (String)request.getSession().getAttribute("codeValue");
        Object codeTime = request.getSession().getAttribute("codeTime");
        if(null != codeTime){
            sessionCodeTime = (Long)codeTime;
        }
    }
}